import 'package:flutter/material.dart';
import 'package:flutter_app/app/models/category.dart';
import '/config/decoders.dart';
import 'package:nylo_framework/nylo_framework.dart';

class CategoryApiService extends NyApiService {
  CategoryApiService({BuildContext? buildContext})
      : super(buildContext, decoders: modelDecoders);

  @override
  String get baseUrl => getEnv('DOUBAN_API');

  /// Example API Request
  Future<Category> fetchData(type) async {
    return await network(
        request: (request) => request.get(
              "/j/search_tags",
              queryParameters: {'type': type},
            ),
        headers: {
          'User-Agent':
              'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
          'Accept': 'text/plain',
          'Content-Type': 'application/text',
        },
        handleFailure: (dioError) {
          print('API request failed: $dioError');
          return Category(tags: []);
        },
        handleSuccess: (Response response) {
          // response - Dio Response object
          dynamic data = response.data;
          return Category.fromJson(data);
        });
  }
}
